<?php
$isReloadable = false;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');
require_once('../../_inc/funct.tabDati.php');

if (reqVar('azione') == 'salva') {
	$msgPag .= salva();
} 
reqDef(cod_sett,'***');

$sCmd1L = "";

$sCmd1R = '';
if (true) {
	$sCmd1R .= "&nbsp;&nbsp;&nbsp;";
	$sCmd1R .= "<a class='cmd1' href=\"javascript:submAz('salva')\" >salva</a>";
}
$sCmd1R .= cmdTorna(); 
$sCmd2R = cmdTorna(); 

testaHtml('', $msgPag, 'ratg');
?>
<script language="JavaScript" type="text/javascript">
  	function submAz(az) {
  		document.frm1.azione.value = az;
  		document.frm1.submit();
  	}
</script>
<?
echo getHtmlForm('frm1','',array('enctype'=>true));
echo getHtmlHidden('azione','...');
echo getHtmlHidden('xsn',XSN);
?>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
	<?=getHtmlRigaRif();?>
   <tr>
      <td class="cmd1" align="right" colspan='20'><?=$sCmd1R?></td>
   </tr>
   <tr>
      <td class="tit1" colspan='20' align='center'>Azienda</td>
   </tr>
<?
$aCamForm = array();
require("_inc/const.campiAnag.php");
echo getHtmlCampiForm($aCamForm);
?>
   <tr>
      <td class="cmd1" align="left" colspan='10'><?=$sCmd1L?></td>
      <td class="cmd1" align="right" colspan='10'><?=$sCmd1R?></td>
   </tr>
</table>
</form>
<?
codaHtml();
exit();


function salva() {
	global $objDB;
	$msg = '';
	if (reqVar('rag_soc')=='') {
		$msg .= _t("ragione sociale obbligatoria")."<br>";
	}
	$_REQUEST['cod_fisc'] = strtoupper(reqVarTrim('cod_fisc'));
	$_REQUEST['cod_cciaa'] = strtoupper(reqVarTrim('cod_cciaa'));
	if (strlen(reqVar('cod_fisc'))!=16 && strlen(reqVar('cod_fisc'))!=11) {
		$msg .= _t("Codice fiscale errato")."<br>";
	}
	if (strlen(reqVar('cod_fisc'))==11 && !is_numeric(reqVar('cod_fisc'))) {
		$msg .= _t("Codice fiscale errato")."<br>";
	}
	$sSqlDel = "SELECT id_azienda FROM rgl_azienda  "
		." WHERE cod_fisc = '".reqVarAS('cod_fisc')."' ";
	$objDB->exec($sSqlDel);
	if ($acX=$objDB->fetch()) {
		$msg .= "cod.fiscale gia' esistente<br>";
	}
	if ($msg != '') {
		return $msg;
	}
	$sSqlDel = "INSERT INTO rgl_azienda SET cod_fisc = '".reqVarAs('cod_fisc')."'"
		.", cod_cciaa = '".reqVarAs('cod_cciaa')."'"
		.", rag_soc = '".reqVarAs('rag_soc')."'"
		.", sede = '".reqVarAs('sede')."'"
		.", cod_sett = '".reqVarAs('cod_sett')."'"
		.", nota = '".reqVarAs('nota')."'"
		;
	$objDB->exec($sSqlDel);
	//return "<pre>".print_r($objDB,1)."</pre>";
	header("Location: ".urlTorna());
	exit();
}
